home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1045 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. From: Fergus Henderson <fjh@cs.mu.oz.au>
  2. Message-ID: <fjh-960412-224718@cs.mu.oz.au>
  3. Path: in2.uu.net!bounce-back
  4. Date: 12 Apr 96 12:47:18 GMT
  5. Approved: fjh@cs.mu.oz.au
  6. Organization: -
  7. Newsgroups: comp.std.c++
  8. Subject: Re: sample auto_ptr template
  9. References: <009A04DA6A831C40.49800EAC@ittpub.nl> <bill-0504961003150001@bgibbons.vip.best.com> <4k4noe$igl@jabba.lehman.com> <KANZE.96Apr9115532@gabi.gabi-soft.fr> <4kjqam$qs6@jabba.lehman.com>
  10. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  11.     iQBFAgUBMW5Q9+EDnX0m9pzZAQGAdgF8DQU6nXgSWckQyauk2lgEZXBxCRFb4Bss
  12.     x48FnVo8jCWgkSzLg5XP47S5R9zqYw5c
  13.     =5KjL
  14.  
  15. ajay@lehman.com (Ajay Kamdar) writes:
  16.  
  17. >The following example demonstrates why allowing exceptions to
  18. >propogate out of destructors is more trouble than it is worth:
  19. >
  20. >   auto_ptr<X>  get_X()
  21. >   {
  22. >      auto_ptr<X> p    = new X;
  23. >      auto_ptr<X> temp = new X;
  24. >      BadIdea     b1; // throws an exception in dtor
  25. >      BadIdea     b2; // throws an exception in dtor
  26. >
  27. >      // ... stuff
  28. >
  29. >      return p;
  30. >   }
  31. >
  32. >When b2 is destructed, it throws an exception. So what happens
  33. >next?
  34. >
  35. >Does the run time system try to continue to destruct b1, temp,
  36. >and p?
  37.  
  38. Yes.
  39.  
  40. >If it does, b1's destructor is also going to thow an
  41. >exception. If I interpret 15.5.1 in theApril '95 CD correctly
  42. >(I don't have access to any later drafts), terminate() is called
  43. >because of the exception propagating out of b1's destructor.
  44.  
  45. That's right.  I'm pretty sure this hasn't changed in the more recent drafts.
  46.  
  47. >If on the other hand the run time system abandons executing
  48. >the other destuctors in get_X() after b2's destructor has
  49. >thrown an exception,
  50.  
  51. Such an implementation would not be conforming.
  52.  
  53. (Incidentally, I agree quite strongly with the arguments voiced by
  54. Ajay Kamdar in this thread.)
  55.  
  56. --
  57. Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
  58. WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
  59. PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
  60. ---
  61. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  62. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  63. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  64. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  65. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  66.